<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="myUtil.deviceCheck" %>
<%@ page import="java.sql.*" %>
<html>
<head>
    <title>person_save</title>
</head>
<body>
<%
    String I = request.getParameter("id");
    int i = Integer.parseInt(I);
    String name = request.getParameter("name");
    String number = request.getParameter("number");
    String type = request.getParameter("type");
    String vendor = request.getParameter("vendor");
    String date = request.getParameter("date");
    String time = request.getParameter("time");
    String afterSales = request.getParameter("afterSales");
    String phone = request.getParameter("phone");
    String illustrate = request.getParameter("illustrate");
    if (deviceCheck.checkS(name, 9) && deviceCheck.checkNumber(number) && deviceCheck.checkS(type, 21) &&
            deviceCheck.checkS(vendor, 21) && deviceCheck.checkS(date, 21) && deviceCheck.checkTime(time) &&
            deviceCheck.checkS(afterSales, 9) && deviceCheck.checkPhone(phone)) {
        Connection conn = (Connection)session.getAttribute("Connection");
        String sql;
        sql = "update device set name=?, number=?, type=?, vendor=?, date=?, time=?, afterSales=?, phone=?, illustrate=? where id="+i;

        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        preparedStatement.setString(1, name);
        preparedStatement.setString(2, number);
        preparedStatement.setString(3, type);
        preparedStatement.setString(4, vendor);
        preparedStatement.setString(5, date);
        preparedStatement.setString(6, time);
        preparedStatement.setString(7, afterSales);
        preparedStatement.setString(8, phone);
        preparedStatement.setString(9, illustrate);


        int rowsUpdated = preparedStatement.executeUpdate();
        if (rowsUpdated > 0) {

        } else {

        }

        response.sendRedirect("device_list.jsp");
    } else {
        request.getRequestDispatcher("device_add.jsp").forward(request, response);
    }

%>
</body>
</html>
